package com.nepu.springboot.springbootrealtime.controller;

import com.nepu.springboot.springbootrealtime.bean.NameValue;
import com.nepu.springboot.springbootrealtime.service.PublisherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 *
 * @author chenshuaijun
 * @create 2022-11-06 10:42
 */
@RestController
public class PublisherController {


    @Autowired
    private PublisherService publisherService;

    /**
     * 统计日活
     * @param td 统计的日期
     * @return 返回统计信息
     */
    @GetMapping("dauRealtime")
    public Map<String,Object> dauRealTime(@RequestParam("td") String td){

        Map<String,Object> result = publisherService.dauRealTime(td);

        return result;
    }

    /**
     * 根据商品和日期进行统计
     * @param itemName
     * @param date
     * @param t
     * @return
     */
    @GetMapping("statsByItem")
    public List<NameValue> statsByItem(
            @RequestParam("itemName") String itemName,
            @RequestParam("date") String date,
            @RequestParam("t") String t){

        List<NameValue> result = publisherService.statsByItem(itemName, date,t);
        return result;
    }

    /**
     * http://bigdata.gmall.com/detailByItem?date=2021-02-02&itemName=%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA&pageNo=1&pageSize=20
     */
    @GetMapping("detailByItem")
    public Map<String,Object> detailByItem(
            @RequestParam("itemName") String itemName,
            @RequestParam("date") String date,
            @RequestParam(value = "pageNo",required = false, defaultValue = "1") String pageNo,
            @RequestParam(value = "pageSize",required = false, defaultValue = "20") String pageSize){
        Map<String,Object> result = publisherService.detailByItem(itemName,date,pageNo,pageSize);
        return result;
    }

}
